package com.lg.curator;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
import org.apache.zookeeper.CreateMode;

public class CuratorTest {
	public static void main(String[] args) throws Exception {
		CuratorFramework newClient = CuratorFrameworkFactory.newClient("127.0.0.1:2181", new RetryNTimes(10, 5000));
		String ZK_PATH = "/zk/stop";
		newClient.start();
//		newClient.delete().forPath(ZK_PATH);
		System.out.println("zk client start successfully!");
		newClient.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(ZK_PATH,"tomcat".getBytes());
		newClient.getChildren().forPath("/").forEach(r -> System.out.println(r));
		byte[] forPath = newClient.getData().forPath(ZK_PATH);
		System.out.println("zk client start successfully!");
		System.out.println(new String(forPath));
		newClient.setData().forPath(ZK_PATH, "curator".getBytes());
		forPath = newClient.getData().forPath(ZK_PATH);
		System.out.println(new String(forPath));
		newClient.delete().forPath(ZK_PATH);
		newClient.delete().forPath("/zk");
		newClient.getChildren().forPath("/").forEach(r->System.out.println(r));
	}
}
